3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * This query action adds a list of a specified user's contributions to the output.
28 class ApiQueryContributions
extends ApiQueryBase
{
30 public function __construct( ApiQuery
$query, $moduleName ) {
31 parent
::__construct( $query, $moduleName, 'uc' );
34 private $params, $multiUserMode, $orderBy, $parentLens;
35 private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
36 $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
37 $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
39 public function execute() {
40 global $wgActorTableSchemaMigrationStage;
42 // Parse some parameters
43 $this->params
= $this->extractRequestParams();
45 $this->commentStore
= CommentStore
::getStore();
47 $prop = array_flip( $this->params
['prop'] );
48 $this->fld_ids
= isset( $prop['ids'] );
49 $this->fld_title
= isset( $prop['title'] );
50 $this->fld_comment
= isset( $prop['comment'] );
51 $this->fld_parsedcomment
= isset( $prop['parsedcomment'] );
52 $this->fld_size
= isset( $prop['size'] );
53 $this->fld_sizediff
= isset( $prop['sizediff'] );
54 $this->fld_flags
= isset( $prop['flags'] );
55 $this->fld_timestamp
= isset( $prop['timestamp'] );
56 $this->fld_patrolled
= isset( $prop['patrolled'] );
57 $this->fld_tags
= isset( $prop['tags'] );
59 // Most of this code will use the 'contributions' group DB, which can map to replica DBs
60 // with extra user based indexes or partioning by user. The additional metadata
61 // queries should use a regular replica DB since the lookup pattern is not all by user.
62 $dbSecondary = $this->getDB(); // any random replica DB
64 // TODO: if the query is going only against the revision table, should this be done?
65 $this->selectNamedDB( 'contributions', DB_REPLICA
, 'contributions' );
67 $sort = ( $this->params
['dir'] == 'newer' ?
'' : ' DESC' );
68 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
70 // Create an Iterator that produces the UserIdentity objects we need, depending
71 // on which of the 'userprefix', 'userids', or 'user' params was
73 $this->requireOnlyOneParameter( $this->params
, 'userprefix', 'userids', 'user' );
74 if ( isset( $this->params
['userprefix'] ) ) {
75 $this->multiUserMode
= true;
76 $this->orderBy
= 'name';
79 // Because 'userprefix' might produce a huge number of users (e.g.
80 // a wiki with users "Test00000001" to "Test99999999"), use a
81 // generator with batched lookup and continuation.
82 $userIter = call_user_func( function () use ( $dbSecondary, $sort, $op, $fname ) {
83 global $wgActorTableSchemaMigrationStage;
86 if ( !is_null( $this->params
['continue'] ) ) {
87 $continue = explode( '|', $this->params
['continue'] );
88 $this->dieContinueUsageIf( count( $continue ) != 4 );
89 $this->dieContinueUsageIf( $continue[0] !== 'name' );
90 $fromName = $continue[1];
92 $like = $dbSecondary->buildLike( $this->params
['userprefix'], $dbSecondary->anyString() );
97 $from = $fromName ?
"$op= " . $dbSecondary->addQuotes( $fromName ) : false;
99 // For the new schema, pull from the actor table. For the
100 // old, pull from rev_user. For migration a FULL [OUTER]
101 // JOIN would be what we want, except MySQL doesn't support
102 // that so we have to UNION instead.
103 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
104 $res = $dbSecondary->select(
106 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
107 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
109 [ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ]
111 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
112 $res = $dbSecondary->select(
114 [ 'actor_id' => 'NULL', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
115 array_merge( [ "rev_user_text$like" ], $from ?
[ "rev_user_text $from" ] : [] ),
117 [ 'DISTINCT', 'ORDER BY' => [ "rev_user_text $sort" ], 'LIMIT' => $limit ]
120 // There are three queries we have to combine to be sure of getting all results:
121 // - actor table (any rows that have been migrated will have empty rev_user_text)
122 // - revision+actor by user id
123 // - revision+actor by name for anons
124 $options = $dbSecondary->unionSupportsOrderAndLimit()
125 ?
[ 'ORDER BY' => [ "user_name $sort" ], 'LIMIT' => $limit ] : [];
127 $subsql[] = $dbSecondary->selectSQLText(
129 [ 'actor_id', 'user_id' => 'COALESCE(actor_user,0)', 'user_name' => 'actor_name' ],
130 array_merge( [ "actor_name$like" ], $from ?
[ "actor_name $from" ] : [] ),
134 $subsql[] = $dbSecondary->selectSQLText(
135 [ 'revision', 'actor' ],
136 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
138 [ "rev_user_text$like", 'rev_user != 0' ],
139 $from ?
[ "rev_user_text $from" ] : []
142 array_merge( [ 'DISTINCT' ], $options ),
143 [ 'actor' => [ 'LEFT JOIN', 'rev_user = actor_user' ] ]
145 $subsql[] = $dbSecondary->selectSQLText(
146 [ 'revision', 'actor' ],
147 [ 'actor_id', 'user_id' => 'rev_user', 'user_name' => 'rev_user_text' ],
149 [ "rev_user_text$like", 'rev_user = 0' ],
150 $from ?
[ "rev_user_text $from" ] : []
153 array_merge( [ 'DISTINCT' ], $options ),
154 [ 'actor' => [ 'LEFT JOIN', 'rev_user_text = actor_name' ] ]
156 $sql = $dbSecondary->unionQueries( $subsql, false ) . " ORDER BY user_name $sort";
157 $sql = $dbSecondary->limitResult( $sql, $limit );
158 $res = $dbSecondary->query( $sql, $fname );
163 foreach ( $res as $row ) {
164 if ( ++
$count >= $limit ) {
165 $fromName = $row->user_name
;
168 yield User
::newFromRow( $row );
170 } while ( $fromName !== false );
172 // Do the actual sorting client-side, because otherwise
173 // prepareQuery might try to sort by actor and confuse everything.
175 } elseif ( isset( $this->params
['userids'] ) ) {
176 if ( !count( $this->params
['userids'] ) ) {
177 $encParamName = $this->encodeParamName( 'userids' );
178 $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
182 foreach ( $this->params
['userids'] as $uid ) {
184 $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' );
189 $this->orderBy
= 'id';
190 $this->multiUserMode
= count( $ids ) > 1;
192 $from = $fromId = false;
193 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
194 $continue = explode( '|', $this->params
['continue'] );
195 $this->dieContinueUsageIf( count( $continue ) != 4 );
196 $this->dieContinueUsageIf( $continue[0] !== 'id' && $continue[0] !== 'actor' );
197 $fromId = (int)$continue[1];
198 $this->dieContinueUsageIf( $continue[1] !== (string)$fromId );
199 $from = "$op= $fromId";
202 // For the new schema, just select from the actor table. For the
203 // old and transitional schemas, select from user and left join
204 // actor if it exists.
205 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
206 $res = $dbSecondary->select(
208 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
209 array_merge( [ 'actor_user' => $ids ], $from ?
[ "actor_id $from" ] : [] ),
211 [ 'ORDER BY' => "user_id $sort" ]
213 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
214 $res = $dbSecondary->select(
216 [ 'actor_id' => 'NULL', 'user_id' => 'user_id', 'user_name' => 'user_name' ],
217 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
219 [ 'ORDER BY' => "user_id $sort" ]
222 $res = $dbSecondary->select(
224 [ 'actor_id', 'user_id', 'user_name' ],
225 array_merge( [ 'user_id' => $ids ], $from ?
[ "user_id $from" ] : [] ),
227 [ 'ORDER BY' => "user_id $sort" ],
228 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
231 $userIter = UserArray
::newFromResult( $res );
232 $batchSize = count( $ids );
235 if ( !count( $this->params
['user'] ) ) {
236 $encParamName = $this->encodeParamName( 'user' );
238 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
241 foreach ( $this->params
['user'] as $u ) {
243 $encParamName = $this->encodeParamName( 'user' );
245 [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName"
249 if ( User
::isIP( $u ) || ExternalUserNames
::isExternal( $u ) ) {
252 $name = User
::getCanonicalName( $u, 'valid' );
253 if ( $name === false ) {
254 $encParamName = $this->encodeParamName( 'user' );
256 [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName"
259 $names[$name] = null;
263 $this->orderBy
= 'name';
264 $this->multiUserMode
= count( $names ) > 1;
266 $from = $fromName = false;
267 if ( $this->multiUserMode
&& !is_null( $this->params
['continue'] ) ) {
268 $continue = explode( '|', $this->params
['continue'] );
269 $this->dieContinueUsageIf( count( $continue ) != 4 );
270 $this->dieContinueUsageIf( $continue[0] !== 'name' && $continue[0] !== 'actor' );
271 $fromName = $continue[1];
272 $from = "$op= " . $dbSecondary->addQuotes( $fromName );
275 // For the new schema, just select from the actor table. For the
276 // old and transitional schemas, select from user and left join
277 // actor if it exists then merge in any unknown users (IPs and imports).
278 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
279 $res = $dbSecondary->select(
281 [ 'actor_id', 'user_id' => 'actor_user', 'user_name' => 'actor_name' ],
282 array_merge( [ 'actor_name' => array_keys( $names ) ], $from ?
[ "actor_id $from" ] : [] ),
284 [ 'ORDER BY' => "actor_name $sort" ]
286 $userIter = UserArray
::newFromResult( $res );
288 if ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
289 $res = $dbSecondary->select(
291 [ 'actor_id' => 'NULL', 'user_id', 'user_name' ],
292 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
296 $res = $dbSecondary->select(
298 [ 'actor_id', 'user_id', 'user_name' ],
299 array_merge( [ 'user_name' => array_keys( $names ) ], $from ?
[ "user_name $from" ] : [] ),
302 [ 'actor' => [ 'LEFT JOIN', 'actor_user = user_id' ] ]
305 foreach ( $res as $row ) {
306 $names[$row->user_name
] = $row;
308 call_user_func_array(
309 $this->params
['dir'] == 'newer' ?
'ksort' : 'krsort', [ &$names, SORT_STRING
]
311 $neg = $op === '>' ?
-1 : 1;
312 $userIter = call_user_func( function () use ( $names, $fromName, $neg ) {
313 foreach ( $names as $name => $row ) {
314 if ( $fromName === false ||
$neg * strcmp( $name, $fromName ) <= 0 ) {
315 $user = $row ? User
::newFromRow( $row ) : User
::newFromName( $name, false );
321 $batchSize = count( $names );
324 // During migration, force ordering on the client side because we're
325 // having to combine multiple queries that would otherwise have
326 // different sort orders.
327 if ( $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_BOTH ||
328 $wgActorTableSchemaMigrationStage === MIGRATION_WRITE_NEW
333 // With the new schema, the DB query will order by actor so update $this->orderBy to match.
334 if ( $batchSize > 1 && $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
335 $this->orderBy
= 'actor';
339 $limit = $this->params
['limit'];
341 while ( $userIter->valid() ) {
343 while ( count( $users ) < $batchSize && $userIter->valid() ) {
344 $users[] = $userIter->current();
348 // Ugh. We have to run the query three times, once for each
349 // possible 'orcond' from ActorMigration, and then merge them all
350 // together in the proper order. And preserving the correct
351 // $hookData for each one.
352 // @todo When ActorMigration is removed, this can go back to a
353 // single prepare and select.
355 foreach ( [ 'actor', 'userid', 'username' ] as $which ) {
356 if ( $this->prepareQuery( $users, $limit - $count, $which ) ) {
358 $res = $this->select( __METHOD__
, [], $hookData );
359 foreach ( $res as $row ) {
360 $merged[] = [ $row, &$hookData ];
364 $neg = $this->params
['dir'] == 'newer' ?
1 : -1;
365 usort( $merged, function ( $a, $b ) use ( $neg, $batchSize ) {
366 if ( $batchSize === 1 ) { // One user, can't be different
368 } elseif ( $this->orderBy
=== 'id' ) {
369 $ret = $a[0]->rev_user
- $b[0]->rev_user
;
370 } elseif ( $this->orderBy
=== 'name' ) {
371 $ret = strcmp( $a[0]->rev_user_text
, $b[0]->rev_user_text
);
373 $ret = $a[0]->rev_actor
- $b[0]->rev_actor
;
378 wfTimestamp( TS_MW
, $a[0]->rev_timestamp
),
379 wfTimestamp( TS_MW
, $b[0]->rev_timestamp
)
384 $ret = $a[0]->rev_id
- $b[0]->rev_id
;
389 $merged = array_slice( $merged, 0, $limit - $count +
1 );
392 if ( $this->fld_sizediff
) {
394 foreach ( $merged as $data ) {
395 if ( $data[0]->rev_parent_id
) {
396 $revIds[] = $data[0]->rev_parent_id
;
399 $this->parentLens
= Revision
::getParentLengths( $dbSecondary, $revIds );
402 foreach ( $merged as $data ) {
404 $hookData = &$data[1];
405 if ( ++
$count > $limit ) {
406 // We've reached the one extra which shows that there are
407 // additional pages to be had. Stop here...
408 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
412 $vals = $this->extractRowInfo( $row );
413 $fit = $this->processRow( $row, $vals, $hookData ) &&
414 $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals );
416 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
422 $this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
426 * Prepares the query and returns the limit of rows requested
427 * @param User[] $users
429 * @param string $which 'actor', 'userid', or 'username'
432 private function prepareQuery( array $users, $limit, $which ) {
433 global $wgActorTableSchemaMigrationStage;
435 $this->resetQueryParams();
436 $db = $this->getDB();
438 $revQuery = Revision
::getQueryInfo( [ 'page' ] );
439 $this->addTables( $revQuery['tables'] );
440 $this->addJoinConds( $revQuery['joins'] );
441 $this->addFields( $revQuery['fields'] );
443 $revWhere = ActorMigration
::newMigration()->getWhere( $db, 'rev_user', $users );
444 if ( !isset( $revWhere['orconds'][$which] ) ) {
447 $this->addWhere( $revWhere['orconds'][$which] );
449 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
450 $orderUserField = 'rev_actor';
451 $userField = $this->orderBy
=== 'actor' ?
'revactor_actor' : 'actor_name';
453 $orderUserField = $this->orderBy
=== 'id' ?
'rev_user' : 'rev_user_text';
454 $userField = $revQuery['fields'][$orderUserField];
456 if ( $which === 'actor' ) {
457 $tsField = 'revactor_timestamp';
458 $idField = 'revactor_rev';
460 $tsField = 'rev_timestamp';
464 // Handle continue parameter
465 if ( !is_null( $this->params
['continue'] ) ) {
466 $continue = explode( '|', $this->params
['continue'] );
467 if ( $this->multiUserMode
) {
468 $this->dieContinueUsageIf( count( $continue ) != 4 );
469 $modeFlag = array_shift( $continue );
470 $this->dieContinueUsageIf( $modeFlag !== $this->orderBy
);
471 $encUser = $db->addQuotes( array_shift( $continue ) );
473 $this->dieContinueUsageIf( count( $continue ) != 2 );
475 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
476 $encId = (int)$continue[1];
477 $this->dieContinueUsageIf( $encId != $continue[1] );
478 $op = ( $this->params
['dir'] == 'older' ?
'<' : '>' );
479 if ( $this->multiUserMode
) {
481 "$userField $op $encUser OR " .
482 "($userField = $encUser AND " .
483 "($tsField $op $encTS OR " .
484 "($tsField = $encTS AND " .
485 "$idField $op= $encId)))"
489 "$tsField $op $encTS OR " .
490 "($tsField = $encTS AND " .
491 "$idField $op= $encId)"
496 // Don't include any revisions where we're not supposed to be able to
498 $user = $this->getUser();
499 if ( !$user->isAllowed( 'deletedhistory' ) ) {
500 $bitmask = Revision
::DELETED_USER
;
501 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
502 $bitmask = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
507 $this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
510 // Add the user field to ORDER BY if there are multiple users
511 if ( count( $users ) > 1 ) {
512 $this->addWhereRange( $orderUserField, $this->params
['dir'], null, null );
516 $this->addTimestampWhereRange( $tsField,
517 $this->params
['dir'], $this->params
['start'], $this->params
['end'] );
519 // Then rev_id for a total ordering
520 $this->addWhereRange( $idField, $this->params
['dir'], null, null );
522 $this->addWhereFld( 'page_namespace', $this->params
['namespace'] );
524 $show = $this->params
['show'];
525 if ( $this->params
['toponly'] ) { // deprecated/old param
528 if ( !is_null( $show ) ) {
529 $show = array_flip( $show );
531 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
532 ||
( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
533 ||
( isset( $show['autopatrolled'] ) && isset( $show['!autopatrolled'] ) )
534 ||
( isset( $show['autopatrolled'] ) && isset( $show['!patrolled'] ) )
535 ||
( isset( $show['top'] ) && isset( $show['!top'] ) )
536 ||
( isset( $show['new'] ) && isset( $show['!new'] ) )
538 $this->dieWithError( 'apierror-show' );
541 $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
542 $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
544 'rc_patrolled = ' . RecentChange
::PRC_UNPATROLLED
,
545 isset( $show['!patrolled'] )
548 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
,
549 isset( $show['patrolled'] )
552 'rc_patrolled != ' . RecentChange
::PRC_AUTOPATROLLED
,
553 isset( $show['!autopatrolled'] )
556 'rc_patrolled = ' . RecentChange
::PRC_AUTOPATROLLED
,
557 isset( $show['autopatrolled'] )
559 $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
560 $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
561 $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
562 $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
564 $this->addOption( 'LIMIT', $limit +
1 );
566 if ( isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ||
567 isset( $show['autopatrolled'] ) ||
isset( $show['!autopatrolled'] ) ||
$this->fld_patrolled
569 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
570 $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' );
573 $isFilterset = isset( $show['patrolled'] ) ||
isset( $show['!patrolled'] ) ||
574 isset( $show['autopatrolled'] ) ||
isset( $show['!autopatrolled'] );
575 $this->addTables( 'recentchanges' );
576 $this->addJoinConds( [ 'recentchanges' => [
577 $isFilterset ?
'JOIN' : 'LEFT JOIN',
579 // This is a crazy hack. recentchanges has no index on rc_this_oldid, so instead of adding
580 // one T19237 did a join using rc_user_text and rc_timestamp instead. Now rc_user_text is
581 // probably unavailable, so just do rc_timestamp.
582 'rc_timestamp = ' . $tsField,
583 'rc_this_oldid = ' . $idField,
588 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled
);
590 if ( $this->fld_tags
) {
591 $this->addTables( 'tag_summary' );
593 [ 'tag_summary' => [ 'LEFT JOIN', [ $idField . ' = ts_rev_id' ] ] ]
595 $this->addFields( 'ts_tags' );
598 if ( isset( $this->params
['tag'] ) ) {
599 $this->addTables( 'change_tag' );
601 [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
603 $this->addWhereFld( 'ct_tag', $this->params
['tag'] );
610 * Extract fields from the database row and append them to a result array
612 * @param stdClass $row
615 private function extractRowInfo( $row ) {
619 if ( $row->rev_deleted
& Revision
::DELETED_TEXT
) {
620 $vals['texthidden'] = true;
624 // Any rows where we can't view the user were filtered out in the query.
625 $vals['userid'] = (int)$row->rev_user
;
626 $vals['user'] = $row->rev_user_text
;
627 if ( $row->rev_deleted
& Revision
::DELETED_USER
) {
628 $vals['userhidden'] = true;
631 if ( $this->fld_ids
) {
632 $vals['pageid'] = intval( $row->rev_page
);
633 $vals['revid'] = intval( $row->rev_id
);
634 // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed?
636 if ( !is_null( $row->rev_parent_id
) ) {
637 $vals['parentid'] = intval( $row->rev_parent_id
);
641 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
643 if ( $this->fld_title
) {
644 ApiQueryBase
::addTitleInfo( $vals, $title );
647 if ( $this->fld_timestamp
) {
648 $vals['timestamp'] = wfTimestamp( TS_ISO_8601
, $row->rev_timestamp
);
651 if ( $this->fld_flags
) {
652 $vals['new'] = $row->rev_parent_id
== 0 && !is_null( $row->rev_parent_id
);
653 $vals['minor'] = (bool)$row->rev_minor_edit
;
654 $vals['top'] = $row->page_latest
== $row->rev_id
;
657 if ( $this->fld_comment ||
$this->fld_parsedcomment
) {
658 if ( $row->rev_deleted
& Revision
::DELETED_COMMENT
) {
659 $vals['commenthidden'] = true;
663 $userCanView = Revision
::userCanBitfield(
665 Revision
::DELETED_COMMENT
, $this->getUser()
668 if ( $userCanView ) {
669 $comment = $this->commentStore
->getComment( 'rev_comment', $row )->text
;
670 if ( $this->fld_comment
) {
671 $vals['comment'] = $comment;
674 if ( $this->fld_parsedcomment
) {
675 $vals['parsedcomment'] = Linker
::formatComment( $comment, $title );
680 if ( $this->fld_patrolled
) {
681 $vals['patrolled'] = $row->rc_patrolled
!= RecentChange
::PRC_UNPATROLLED
;
682 $vals['autopatrolled'] = $row->rc_patrolled
== RecentChange
::PRC_AUTOPATROLLED
;
685 if ( $this->fld_size
&& !is_null( $row->rev_len
) ) {
686 $vals['size'] = intval( $row->rev_len
);
689 if ( $this->fld_sizediff
690 && !is_null( $row->rev_len
)
691 && !is_null( $row->rev_parent_id
)
693 $parentLen = isset( $this->parentLens
[$row->rev_parent_id
] )
694 ?
$this->parentLens
[$row->rev_parent_id
]
696 $vals['sizediff'] = intval( $row->rev_len
- $parentLen );
699 if ( $this->fld_tags
) {
700 if ( $row->ts_tags
) {
701 $tags = explode( ',', $row->ts_tags
);
702 ApiResult
::setIndexedTagName( $tags, 'tag' );
703 $vals['tags'] = $tags;
709 if ( $anyHidden && $row->rev_deleted
& Revision
::DELETED_RESTRICTED
) {
710 $vals['suppressed'] = true;
716 private function continueStr( $row ) {
717 if ( $this->multiUserMode
) {
718 switch ( $this->orderBy
) {
720 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
722 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
724 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
727 return "$row->rev_timestamp|$row->rev_id";
731 public function getCacheMode( $params ) {
732 // This module provides access to deleted revisions and patrol flags if
733 // the requester is logged in
734 return 'anon-public-user-private';
737 public function getAllowedParams() {
740 ApiBase
::PARAM_DFLT
=> 10,
741 ApiBase
::PARAM_TYPE
=> 'limit',
742 ApiBase
::PARAM_MIN
=> 1,
743 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
744 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
747 ApiBase
::PARAM_TYPE
=> 'timestamp'
750 ApiBase
::PARAM_TYPE
=> 'timestamp'
753 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
756 ApiBase
::PARAM_TYPE
=> 'user',
757 ApiBase
::PARAM_ISMULTI
=> true
760 ApiBase
::PARAM_TYPE
=> 'integer',
761 ApiBase
::PARAM_ISMULTI
=> true
763 'userprefix' => null,
765 ApiBase
::PARAM_DFLT
=> 'older',
766 ApiBase
::PARAM_TYPE
=> [
770 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-direction',
773 ApiBase
::PARAM_ISMULTI
=> true,
774 ApiBase
::PARAM_TYPE
=> 'namespace'
777 ApiBase
::PARAM_ISMULTI
=> true,
778 ApiBase
::PARAM_DFLT
=> 'ids|title|timestamp|comment|size|flags',
779 ApiBase
::PARAM_TYPE
=> [
791 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
794 ApiBase
::PARAM_ISMULTI
=> true,
795 ApiBase
::PARAM_TYPE
=> [
807 ApiBase
::PARAM_HELP_MSG
=> [
808 'apihelp-query+usercontribs-param-show',
809 $this->getConfig()->get( 'RCMaxAge' )
814 ApiBase
::PARAM_DFLT
=> false,
815 ApiBase
::PARAM_DEPRECATED
=> true,
820 protected function getExamplesMessages() {
822 'action=query&list=usercontribs&ucuser=Example'
823 => 'apihelp-query+usercontribs-example-user',
824 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
825 => 'apihelp-query+usercontribs-example-ipprefix',
829 public function getHelpUrls() {
830 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';